//
//  VIZMainTBC.swift
//  VIZ微博
//
//  Created by 位立志 on 16/4/7.
//  Copyright © 2016年 位立志. All rights reserved.
//

import UIKit

class VIZMainTBC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //设置自定义的tabbar
        let mainTabBar = VIZTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        //plus添加点击事件
        mainTabBar.plusButton.addTarget(self, action: "plusClick", forControlEvents: .TouchUpInside)
        
        
        addChildViewControllers()
    }
    
        
    func plusClick(){
        
        //print("plusClick点击了")
        
    }
    
    
    //添加所有的子控制器
    private func addChildViewControllers() {
        
        addChildViewController(HomeVC(),title: "首页", imageName: "tabbar_home")
        addChildViewController(DiscoveryTableVC(),title: "发现", imageName: "tabbar_discover")
        addChildViewController(MessageTableVC(),title: "消息", imageName: "tabbar_message_center")
        addChildViewController(ProfileTableVC(),title: "我", imageName: "tabbar_profile")
        
    }
    
    //自定义封装添加子控制器
    private func addChildViewController(vc:UIViewController, title:String, imageName:String) {
        
        let nav = VIZViewNavugationVC(rootViewController: vc)
        
        nav.navigationBar.setBackgroundImage(UIImage(named: "1"), forBarMetrics: .Default)
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //设置选中,注意要设置选中的图片的Model
        vc.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //更改字体
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        //tabBar.tintColor = UIColor.orangeColor()
        
        addChildViewController(nav)
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

}
